
package model;
import java.io.Serializable;
import java.util.ArrayList;

/**
 * The Trail Maintenance Job Class.
 * @author Kyle Richardson
 */
public class Job implements Serializable{
	/**
	 * The classes serializable ID.
	 */
	private static final long serialVersionUID =
		5080699180395669252L;
	/**
	 * ArrayList of all the verified group leaders.
	 */
	private ArrayList<Volunteer> myGroupLeaders;
	/**
	 * ArrayList of all the Volunteers in a work party.
	 */
	private ArrayList<Volunteer> myWorkParty;
	/**
	 * The max number of Volunteers allowed in a work party.
	 */
	private int myMaxVolunteers;
	/**
	 * The max number of group leaders allowed in a work
	 * party.
	 */
	private int myMaxGroupLeaders;
	/**
	 * The job's Difficulty level.
	 */
	private int myDifficultyLevel;
	/**
	 * The name of the trail maintenance job.
	 */
	private String myName;
	/**
	 * The time of the TMJ.
	 */
	private int myTime;
	/**
	 * The LMA that requested this Job.
	 */
	private LMA myLMA;
	/**
	 * A description of the job.
	 */
	private String myDescription;
	
	/**
	 * The start year of the job.
	 */
	private int myStartYear;
	/**
	 * The start month of the job.
	 */
	private int myStartMonth;
	/**
	 * The start day of the job.
	 */
	private int myStartDay;
	
	/**
	 * The end year of the job.
	 */
	private int myEndYear;
	/**
	 * The end month of the job.
	 */
	private int myEndMonth;
	/**
	 * The end day of the job.
	 */
	private int myEndDay;
	
	/**
	 * Creates the Job object.
	 * @param theName The name of the job.
	 * @param theDifficultyLevel the difficulty level of 
	 * the job.
	 * @param theTime the time of the job.
	 * @param theLMA the LMA that requested the job.
	 * @param theMaxVol the max number of volunteers for
	 * the job.
	 * @param theMaxGL the max number of group leaders for
	 * a job.
	 * @param theDescription the description of the job.
	 */
	public Job(String theName, int theDifficultyLevel,
			int theTime, LMA theLMA, int theMaxVol,
			int theMaxGL, String theDescription)
	{
		myName = theName;
		myDifficultyLevel = theDifficultyLevel;
		myTime = theTime;
		myMaxVolunteers = theMaxVol;
		myMaxGroupLeaders = theMaxGL;
		myWorkParty = new ArrayList<Volunteer>();
		myGroupLeaders = new ArrayList<Volunteer>();
		myLMA = theLMA;
		myDescription = theDescription;
		myStartYear = 0;
		myStartMonth = 0;
		myStartDay = 0;
		myEndYear = 0;
		myEndMonth = 0;
		myEndDay = 0;
		
	}
	
	/**
	 * Schedules the job.
	 * @param theStartYear the start year of the job.
	 * @param theStartMonth the start month of the job.
	 * @param theStartDate the start date of the job.
	 * @param theEndYear the end year of the job.
	 * @param theEndMonth the end month of the job.
	 * @param theEndDate the end date of the job.
	 * @return Returns true if successful, otherwise false.
	 */
	public boolean schduleJob(final int theStartYear,
			final int theStartMonth,
			final int theStartDate, final int theEndYear,
			final int theEndMonth, final int theEndDate)
	{
		
		myStartYear = theStartYear;
		myStartMonth = theStartMonth;
		myStartDay = theStartDate;
		myEndYear = theEndYear;
		myEndMonth = theEndMonth;
		myEndDay = theEndDate;

		return true;
	}
	
	/**
	 * @return Returns the name of the job.
	 */
	public String getName()
	{
		return myName;
	}
	
	/**
	 * @return Returns the start year of the job.
	 */
	public int getStartYear()
	{
		return myStartYear; 
	}
	
	/**
	 * @return Returns the start month of the job.
	 */
	public int getStartMonth()
	{
		return myStartMonth; 
	}
	
	/**
	 * @return Returns the start day of the job.
	 */
	public int getStartDay()
	{
		return myStartDay; 
	}
	
	/**
	 * @return Returns the end year of the job.
	 */
	public int getEndYear()
	{
		return myEndYear; 
	}
	
	/**
	 * @return Returns the end month of the job.
	 */
	public int getEndMonth()
	{
		return myEndMonth; 
	}
	
	/**
	 * @return Returns the end day of the job.
	 */
	public int getEndDay()
	{
		return myEndDay; 
	}
	
	/**
	 * @return Returns the max number of volunteers
	 * for a job.
	 */
	public int getMaxVolunteers()
	{
		return myMaxVolunteers;
	}
	
	/**
	 * @return Returns the max number of group leaders
	 *  for a job.
	 */
	public int getMaxGroupLeaders()
	{
		return myMaxGroupLeaders;
	}
	
	/**
	 * 
	 * @return Returns the number of group leaders
	 *  signed up for the job.
	 */
	public int getSignedUpGroupLeaders()
	{
		return myGroupLeaders.size();
	}
	
	/**
	 * @return Returns the difficulty level of the job.
	 */
	public int getDifficultyLevel()
	{
		return myDifficultyLevel;
	}
	
	/**
	 * @return Returns the time of the job.
	 */
	public int getTime()
	{
		return myTime;
	}
	
	/**
	 * @return Returns an ArrayList of the group leaders.
	 */
	public ArrayList<Volunteer> getGroupLeaders()
	{
		return myGroupLeaders;
	}
	
	/**
	 * @return Returns the LMA that requested the Job.
	 */
	public LMA getLMA()
	{
		return myLMA;
	}
	
	/**
	 * @return Returns the description of the job.
	 */
	public String getDescription()
	{
		return myDescription;
	}
	
	/**
	 * 
	 * @return Returns an ArrayList of the Volunteers
	 *  in the work party.
	 */
	public ArrayList<Volunteer> getWorkParty()
	{
		return myWorkParty;
	}
	
	/**
	 * Allows a Volunteer to sign up for the Job.
	 * @param theVol the Volunteer signing up for the job.
	 * @return Returns true if successful, otherwise false.
	 */
	public boolean signupForJobAsVol(final Volunteer theVol)
	{
		boolean check = false;
		if(myWorkParty.size() < myMaxVolunteers &&
				!myWorkParty.contains(theVol))
		{	
			myWorkParty.add(theVol);
			check = true;
		}
		return check;
	}
	
	/**
	 * Allows a verified Volunteer to sign up for the Job
	 * as a Group Leader.
	 * @param theVol the Volunteer signing up.
	 * @return Returns true if successful, otherwise false.
	 */
	public boolean signupForJobAsGL(final Volunteer theVol)
	{
		boolean check = false;
		if(theVol.isGL() && myGroupLeaders.size()
				< myMaxGroupLeaders &&
				!myWorkParty.contains(theVol))
		{	
			myGroupLeaders.add(theVol);
			myWorkParty.add(theVol);
			check = true;
		}
		return check;
	}
	
	/**
	 * Checks if a Volunteer is already registered for a 
	 * job.
	 * @param theVol The Volunteer being checked.
	 * @return true if the Volunteer has already registered.
	 */
	public boolean isSignedUpFor(final Volunteer theVol)
	{
		return myWorkParty.contains(theVol);
	}
}
